﻿Imports Microsoft.VisualBasic
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System.Web.UI.HtmlControls

Public Class MenuCabecalhoCarga
    Inherits System.Web.UI.WebControls.WebControl
    Implements INamingContainer

    Protected WithEvents miMenu As New Menu
    Protected WithEvents pnlPanel As New Panel
    Protected WithEvents imgImagem As New Image
    Protected WithEvents hpLogOn As New HyperLink
    Protected WithEvents hpCadastrese As New HyperLink
    Protected WithEvents hpSair As New HyperLink
    Protected WithEvents hpCA As New HyperLink
    Protected WithEvents hpMI As New HyperLink
    Protected WithEvents hpEC As New HyperLink

    Protected WithEvents lblSaudacao As New Label
    Protected WithEvents lblTexto1 As New Label
    Protected WithEvents lbltexto2 As New Label
    Protected WithEvents lblCA As New Label
    Protected WithEvents lblMI As New Label

    Dim tblMenu As New Table
    Dim MenuRow1 As New TableRow
    Dim MenuRow2 As New TableRow
    Dim MenuRow3 As New TableRow
    Dim MenuCel1 As New TableCell
    Dim MenuCel2 As New TableCell
    Dim MenuCel3 As New TableCell
    Dim MenuCel4 As New TableCell

    Dim tblLogado As New Table
    Dim LogadoRow As New TableRow
    Dim LogadoCel1 As New TableCell
    Dim LogadoCel2 As New TableCell
    Dim LogadoCel3 As New TableCell

    Private strLinkHome As String = "http://www.imovelweb.com.br"
    Private strCorBordaInferior As Drawing.Color
    Private strCorBordaSuperior As Drawing.Color

    Private BolLogOnLightBox As Boolean
    Private BolCadastreseLightBox As Boolean


    Private strClasseFuncionalidade As String = String.Empty

    Private strClasseCarga As String = String.Empty
    Private strPropriedadeCarga As String = String.Empty


#Region "Propriedades"

    <DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
      Editor(GetType(MenuItemCollection), GetType(System.Drawing.Design.UITypeEditor)), _
      PersistenceMode(PersistenceMode.InnerDefaultProperty)> _
    Public ReadOnly Property Items() As MenuItemCollection
        Get
            EnsureChildControls()
            Return Me.miMenu.Items
        End Get

    End Property

    <Category("Design")> _
  Public Property ClasseFuncionalidade() As String
        Get
            Return strClasseFuncionalidade
        End Get
        Set(ByVal Value As String)

            strClasseFuncionalidade = Value
        End Set
    End Property

    <Category("Design")> _
   Public Overrides Property CssClass() As String
        Get
            Return miMenu.CssClass
        End Get
        Set(ByVal Value As String)

            miMenu.CssClass = Value
        End Set
    End Property

    <Category("Design")> _
    Public Overrides Property Height() As Unit
        Get

            Return pnlPanel.Height
        End Get
        Set(ByVal Value As Unit)

            pnlPanel.Height = Value
        End Set
    End Property

    <Category("Design")> _
    Public Overrides Property Width() As Unit
        Get
            Return pnlPanel.Width
        End Get
        Set(ByVal Value As Unit)

            pnlPanel.Width = Value
        End Set
    End Property

    <Category("Design")> _
    Public Property ImageUrl() As String
        Get
            Return imgImagem.ImageUrl
        End Get
        Set(ByVal Value As String)

            imgImagem.ImageUrl = Value

        End Set
    End Property

    <Category("Design")> _
   Public Property LinkHome() As String
        Get
            Return strLinkHome
        End Get
        Set(ByVal value As String)
            strLinkHome = value
        End Set
    End Property

    <Category("Design")> _
   Public Property ImagemVAlign() As VerticalAlign
        Get
            Return MenuCel1.VerticalAlign
        End Get
        Set(ByVal value As VerticalAlign)
            MenuCel1.VerticalAlign = value
        End Set
    End Property

    <Category("Design")> _
    Public Property CorTracoInferior() As Drawing.Color
        Get
            Return strCorBordaInferior
        End Get
        Set(ByVal value As Drawing.Color)
            strCorBordaInferior = value
        End Set
    End Property

    <Category("Design")> _
  Public Property URLLogOn() As String
        Get
            Return hpLogOn.NavigateUrl
        End Get
        Set(ByVal value As String)
            hpLogOn.NavigateUrl = value
        End Set
    End Property

    <Category("Design")> _
Public Property LogOnLightBox() As Boolean
        Get
            Return Me.BolLogOnLightBox
        End Get
        Set(ByVal value As Boolean)
            Me.BolLogOnLightBox = value
        End Set
    End Property

    <Category("Design")> _
Public Property CadastreseLightBox() As Boolean
        Get
            Return Me.BolCadastreseLightBox
        End Get
        Set(ByVal value As Boolean)
            Me.BolCadastreseLightBox = value
        End Set
    End Property

    <Category("Design")> _
  Public Property URLCadastro() As String
        Get
            Return hpCadastrese.NavigateUrl
        End Get
        Set(ByVal value As String)
            hpCadastrese.NavigateUrl = value
        End Set
    End Property


    <Category("Design")> _
Public Property URLSair() As String
        Get
            Return hpSair.NavigateUrl
        End Get
        Set(ByVal value As String)
            hpSair.NavigateUrl = value
        End Set
    End Property


    <Category("Design")> _
 Public Property URLCentralAnunciante() As String
        Get
            Return hpCA.NavigateUrl
        End Get
        Set(ByVal value As String)
            hpCA.NavigateUrl = value
        End Set
    End Property

    <Category("Design")> _
Public Property URLMeuImovelWeb() As String
        Get
            Return hpMI.NavigateUrl
        End Get
        Set(ByVal value As String)
            hpMI.NavigateUrl = value
        End Set
    End Property

    <Category("Design")> _
Public Property URLEditarCadastro() As String
        Get
            Return hpEC.NavigateUrl
        End Get
        Set(ByVal value As String)
            hpEC.NavigateUrl = value
        End Set
    End Property

    <Category("Design")> _
   Public Property CorTracoLogOn() As Drawing.Color
        Get
            Return strCorBordaSuperior
        End Get
        Set(ByVal value As Drawing.Color)
            strCorBordaSuperior = value
        End Set
    End Property

    <Category("Design")> _
  Public Property ToolTipLogOn() As String
        Get
            Return hpLogOn.ToolTip
        End Get
        Set(ByVal value As String)
            hpLogOn.ToolTip = value
        End Set
    End Property

    <Category("Design")> _
  Public Property ToolTipCadastrese() As String
        Get
            Return hpCadastrese.ToolTip
        End Get
        Set(ByVal value As String)
            hpCadastrese.ToolTip = value
        End Set
    End Property

    <Category("Design")> _
Public Property ToolTipCentralAnunciante() As String
        Get
            Return hpCA.ToolTip
        End Get
        Set(ByVal value As String)
            hpCA.ToolTip = value
        End Set
    End Property


    <Category("Design")> _
Public Property ToolTipMeuImovelWeb() As String
        Get
            Return hpMI.ToolTip
        End Get
        Set(ByVal value As String)
            hpMI.ToolTip = value
        End Set
    End Property

    <Category("Design")> _
Public Property ToolTipEditarCadastro() As String
        Get
            Return hpEC.ToolTip
        End Get
        Set(ByVal value As String)
            hpEC.ToolTip = value
        End Set
    End Property

    <Category("Design")> _
Public Property CssSaudacao() As String
        Get
            Return lblSaudacao.CssClass
        End Get
        Set(ByVal value As String)
            lblSaudacao.CssClass = value
        End Set
    End Property

    <Category("Design")> _
Public Property CssTexto() As String
        Get
            Return lblTexto1.CssClass
        End Get
        Set(ByVal value As String)
            lblTexto1.CssClass = value
        End Set
    End Property

    <Category("Classe de Negócio")> _
    Public Property ClasseCarga() As String
        Get
            Return strClasseCarga
        End Get
        Set(ByVal value As String)
            strClasseCarga = value.Trim.ToUpper(System.Globalization.CultureInfo.CurrentCulture)
        End Set
    End Property

    <Category("Classe de Negócio")> _
    Public Property PropriedadeCarga() As String
        Get
            Return strPropriedadeCarga
        End Get
        Set(ByVal value As String)
            strPropriedadeCarga = value
        End Set
    End Property


#End Region

    Protected Overrides Sub LoadViewState(ByVal savedState As Object)

        MyBase.LoadViewState(savedState(0))

        'Dim dadosViewState() As Object

        'dadosViewState = savedState(1)

        'Me.txtValor.Text = dadosViewState(0)
        'Me.bolObrigatorio = dadosViewState(1)
        'Me.tvTipoValor = dadosViewState(2)
        'Me.strClasseCarga = dadosViewState(3)
        'Me.strPropriedadeCarga = dadosViewState(4)
        'Me.bolReadOnly = dadosViewState(5)
        'Me.intPosicaoTitulo = dadosViewState(6)
        'Me.strToolTip = dadosViewState(7)

    End Sub

    Protected Overrides Function SaveViewState() As Object

        Dim savedState(1) As Object

        savedState(0) = MyBase.SaveViewState()

        'Dim dadosViewState(7) As Object

        'dadosViewState(0) = Me.txtValor.Text
        'dadosViewState(1) = Me.bolObrigatorio
        'dadosViewState(2) = Me.tvTipoValor
        'dadosViewState(3) = Me.strClasseCarga
        'dadosViewState(4) = Me.strPropriedadeCarga
        'dadosViewState(5) = Me.bolReadOnly
        'dadosViewState(6) = Me.intPosicaoTitulo
        'dadosViewState(7) = Me.strToolTip

        'savedState(1) = dadosViewState
        Return savedState

    End Function

    Public Sub New()

        pnlPanel.Width = Unit.Pixel(1024)
        strCorBordaInferior = Drawing.Color.Green
        pnlPanel.Style.Add("border-bottom-width", "2px")
        pnlPanel.Style.Add("border-bottom-style", "solid")

        MenuCel1.RowSpan = 3
        MenuCel1.VerticalAlign = VerticalAlign.Bottom
        imgImagem.ImageAlign = ImageAlign.Left

        MenuCel2.VerticalAlign = VerticalAlign.Top
        MenuCel2.HorizontalAlign = HorizontalAlign.Right
        lblSaudacao.Text = "Bem Vindo. "
        lblTexto1.Text = "Faça seu "
        lbltexto2.Text = " ou "
        hpLogOn.Text = "Login"
        hpCadastrese.Text = "Registre-se"

        MenuCel3.HorizontalAlign = HorizontalAlign.Right
        tblLogado.Width = Unit.Pixel(400)
        strCorBordaSuperior = Drawing.Color.Black
        tblLogado.Style.Add("border-bottom-style", "solid")
        tblLogado.Style.Add("border-top-width", "1px")
        tblLogado.Style.Add("padding-bottom", "10px")
        tblLogado.Style.Add("text-align", "center")
        hpEC.Text = "editar cadastro"
        hpCA.Text = "00 Imóveis Anunciados"
        hpMI.Text = "00 Imóveis Favoritos"
        lblCA.Text = "Central do Anunciante"
        lblMI.Text = "Meu ImovelWeb"

        MenuCel4.HorizontalAlign = HorizontalAlign.Right
        MenuCel4.VerticalAlign = VerticalAlign.Bottom
        miMenu.Orientation = Orientation.Horizontal
        miMenu.CssClass = "Menu"

    End Sub

    Protected Overrides Sub CreateChildCOntrols()

        MenuCel4.Controls.Add(miMenu)

        LogadoCel2.Text = String.Empty
        LogadoCel1.Text = String.Empty
        LogadoCel3.Controls.Add(hpEC)
        LogadoCel2.Controls.AddAt(0, lblMI)
        LogadoCel2.Controls.AddAt(1, New HtmlGenericControl("<br>"))
        'LogadoCel2.Text.Insert(1, "<br>")
        LogadoCel2.Controls.AddAt(2, hpMI)
        LogadoCel1.Controls.AddAt(0, lblCA)
        LogadoCel1.Controls.AddAt(1, New HtmlGenericControl("<br>"))
        'LogadoCel1.Text.Insert(1, "<br>")
        LogadoCel1.Controls.AddAt(2, hpCA)

        LogadoRow.Cells.AddAt(0, LogadoCel1)
        LogadoRow.Cells.AddAt(1, LogadoCel2)
        LogadoRow.Cells.AddAt(2, LogadoCel3)

        tblLogado.Rows.Add(LogadoRow)

        MenuCel1.Text = String.Empty

        MenuCel3.Controls.Add(tblLogado)

        MenuCel2.Controls.AddAt(0, lblSaudacao)
        MenuCel2.Controls.AddAt(1, lblTexto1)
        MenuCel2.Controls.AddAt(2, hpLogOn)
        MenuCel2.Controls.AddAt(3, lbltexto2)
        MenuCel2.Controls.AddAt(4, hpCadastrese)

        LogadoCel1.Controls.AddAt(0, New HtmlAnchor())
        'MenuCel1.Text.Insert(0, "<a href='" & strLinkHome & "'>")
        MenuCel1.Controls.AddAt(0, imgImagem)
        'MenuCel1.Text.Insert(2, "</a>")


        MenuRow3.Cells.AddAt(0, MenuCel4)
        MenuRow2.Cells.AddAt(0, MenuCel3)
        MenuRow1.Cells.AddAt(0, MenuCel1)
        MenuRow1.Cells.AddAt(1, MenuCel2)

        tblMenu.Rows.AddAt(0, MenuRow1)
        tblMenu.Rows.AddAt(1, MenuRow2)
        tblMenu.Rows.AddAt(2, MenuRow3)

        pnlPanel.Controls.Add(tblMenu)

        tblMenu.Rows.Add(New TableRow)

        Me.Controls.Add(pnlPanel)

    End Sub

    Private Sub MenuCabecalhoCarga_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        pnlPanel.Style.Add("border-bottom-color", strCorBordaInferior.ToString)
        Me.tblMenu.Width = Me.pnlPanel.Width
        Me.lbltexto2.CssClass = Me.lblTexto1.CssClass
        tblLogado.Style.Add("border-bottom-color", strCorBordaSuperior.ToString)
    End Sub


    Protected Overrides Sub render(ByVal writer As HtmlTextWriter)

        EnsureChildControls()
        RenderChildren(writer)
    End Sub

    'Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)

    '    Dim PaginaPai As Componentes.Page

    '    If TypeOf Me.Page Is Componentes.Page Then

    '        PaginaPai = Me.Page

    '        If TypeOf Me.Page Is Componentes.Page Then

    '            PaginaPai = Me.Page

    '            If Me.strClasseCarga = PaginaPai.ClasseCarga And Me.strClasseCarga <> String.Empty Then
    '                If Not PaginaPai.CarregarControles Then
    '                    PaginaPai.AtualizarValorControle(Me.strPropriedadeCarga, Diversos.ConversaoTipos(Me.txtValor.Text, Me.TipoValor))
    '                End If
    '            End If
    '        End If

    '    End If

    'End Sub

    'Protected Overrides Sub OnPreRender(ByVal e As EventArgs)

    '    Dim PaginaPai As Componentes.Page

    '    If TypeOf Me.Page Is Componentes.Page Then

    '        PaginaPai = Me.Page

    '        If Me.strClasseCarga = PaginaPai.ClasseCarga And Me.strClasseCarga <> String.Empty Then

    '            If TypeOf Me.Page Is Componentes.Page Then

    '                PaginaPai = Me.Page

    '                If PaginaPai.CarregarControles Or PaginaPai.LimparControles Then

    '                    If TypeOf PaginaPai.CarregarValorControle(Me.strPropriedadeCarga) Is Date And PaginaPai.CarregarValorControle(Me.strPropriedadeCarga) <> Nothing Then

    '                        If Me.strMascaraInput.IndexOf(":", System.StringComparison.CurrentCulture) >= 0 Then
    '                            Me.txtValor.Text = CDate(PaginaPai.CarregarValorControle(Me.strPropriedadeCarga)).ToString("dd/MM/yyyy HH:mm", System.Globalization.CultureInfo.CurrentCulture)
    '                        Else
    '                            Me.txtValor.Text = CDate(PaginaPai.CarregarValorControle(Me.strPropriedadeCarga)).ToString("dd/MM/yyyy", System.Globalization.CultureInfo.CurrentCulture)
    '                        End If
    '                    ElseIf Not TypeOf PaginaPai.CarregarValorControle(Me.strPropriedadeCarga) Is Date And Not PaginaPai.CarregarValorControle(Me.strPropriedadeCarga) Is Nothing Then
    '                        If Me.strFormatoApresentacao.Trim = String.Empty Then
    '                            Me.txtValor.Text = PaginaPai.CarregarValorControle(Me.strPropriedadeCarga)
    '                        Else
    '                            Me.txtValor.Text = Format(PaginaPai.CarregarValorControle(Me.strPropriedadeCarga), strFormatoApresentacao)
    '                        End If
    '                    End If

    '                Else

    '                    PaginaPai.AtualizarValorControle(Me.strPropriedadeCarga, Me.txtValor.Text)

    '                End If

    '                If Not PaginaPai.Edicao And Not PaginaPai.Insercao Then
    '                    Me.txtValor.Enabled = False

    '                Else

    '                    Me.txtValor.Enabled = True

    '                End If

    '            End If

    '        End If

    '    End If


    '    If Me.strToolTip <> String.Empty Then
    '        Me.txtValor.ToolTip = strToolTip
    '        Me.lblTitulo.ToolTip = strToolTip
    '    End If

    '    MyBase.OnPreRender(e)

    'End Sub

    Private Sub MenuCabecalhoCarga_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        Me.tblLogado.Visible = False
    End Sub
End Class

